<template>
	<view class="content">
		
		
		<view style="background-color: #eeeeee;height: 2upx;"></view>
		
		<view class="headCheck">
			
			<view class="bountsHeaderView" v-if="isMemberWeb==true">给自己转账 ：</view>
			
				<view class="checkBox" @click="checkbox(0)" v-if="isMemberWeb==true">
					
					<view class="pointView" v-if="isCheckValue==0"></view>
					
				</view>
				
				<view class="bountsHeaderView">给别人转账 ：</view>
				
					<view class="checkBox" @click="checkbox(1)">
						
						<view class="pointView" v-if="isCheckValue==1"></view>
						
					</view>
			
		</view>
		
		
		<view class="headCheck" style="margin-top: 0upx;" v-if="isCheckValue==1&&isMemberWeb==true">
			
			<view class="bountsHeaderView" >从余额转账 ：</view>
			
				<view class="checkBox" @click="checkbox2(0)" v-if="isMemberWeb==true">
					
					<view class="pointView" v-if="fromAccountValue==0"></view>
					
				</view>
				
				<view class="bountsHeaderView">从奖金转账 ：</view>
				
					<view class="checkBox" @click="checkbox2(1)">
						
						<view class="pointView" v-if="fromAccountValue==1"></view>
						
					</view>
			
		</view>
		
		
		
		<view class="headCheck" style="margin-top: 0upx;">
			
			<view class="bountsHeaderView" v-if="isCheckValue==1&& fromAccountValue==0">账户余额 ：</view>
			
			<view class="suplusAccountView" v-if="isCheckValue==1&& fromAccountValue==0">{{userinfo.balance}}</view>
			
			
			<view class="bountsHeaderView" v-if="isCheckValue==1&& fromAccountValue==1">奖金余额 ：</view>
			
			<view class="suplusAccountView" v-if="isCheckValue==1&& fromAccountValue==1">{{userinfo.bonus}}</view>
			
			
			
			<view class="bountsHeaderView" v-if="isCheckValue==0">奖金余额 ：</view>
			
			<view class="suplusAccountView" v-if="isCheckValue==0">{{userinfo.bonus}}</view>
			
			
	
		</view>
	


	<view class="headCheck" style="margin-top: 0upx;" >
		
		<view class="bountsHeaderView">转账金额 ：</view>
		
		<input class="cell-bd-input" type="text" v-model="transformValue" placeholder="请输入转账金额" />
		
			
		
		
	</view>
	
	
	
	<view class="headCheck" style="margin-top: 0upx;" v-if="isCheckValue==1">
		
		<view class="bountsHeaderView">转出账户 ：</view>
		
		<input class="cell-bd-input" type="text" v-model="moneyToUserName" placeholder="请输入转出账户" />
		
			
		
		
	</view>
	
	
	
	<view class="headCheck" style="margin-top: 0upx;" v-if="isCheckValue==1">
		
		<view class="bountsHeaderView">账户昵称 ：</view>
		
		<input class="cell-bd-input" type="text" v-model="moneyToNickname" placeholder="请输入转入账户昵称" />
		
			
		
		
	</view>



	<view class="headCheck" style="margin-top: 0upx;" >
		
		<view class="bountsHeaderView">手机号 :</view>
		
		<!-- <input class="cell-bd-input" type="text" v-model="transformValue" placeholder="请输入转账金额" /> -->
		
			
		<view class="bountsHeaderView" >{{showPhone}}</view>
		
		
	</view>
	
	
	<view class="headCheck" style="margin-top: 0upx;" >
		
	<view class="bountsHeaderView">验证码 :</view>
	

		<input class="cell-bd-input" type="text" v-model="code" placeholder="请输入验证码" style="margin-left: 30upx;"/>
		<view class="btn2" @click="sendCode" v-if="verification">发送验证码</view>
		<view class="btn2" v-if="!verification">{{ timer }} 秒后重新获取</view>
	
		
	
	
		
	</view>
	
	

			
	
		<view class="button-bottom">
			<button class="btn btn-square btn-b" hover-class="btn-hover2" @click="submitHandler()" :disabled='submitStatus'
			 :loading='submitStatus'>转账</button>
		</view>
	</view>
</template>

<script>
	
	import {isMemberWeb} from '@/config/config.js'
	
	
	export default {
		data() {
			return {
				submitStatus: false,
				mobile: '', // 原手机号
				code: '',   // 原手机号验证码
				transformValue : '',
				
				user_name: '',
				verification: true, // 通过v-show控制显示获取还是倒计时
				new_verification: true, // 通过v-show控制显示获取还是倒计时
				timer: 60, // 定义初始时间为60s
				
				isCheckValue : 0,
				
				moneyToUserName : '',
				
				fromAccountValue : 0,
				
				showPhone : '',
				
				userinfo : '',
				
				isMemberWeb : isMemberWeb,
				
				moneyToNickname : ''
		
			}
		},
		computed: {
		
		},
		methods: {
			
			checkbox(value){
				console.log(value);
				this.isCheckValue = value;
			},
			
			checkbox2(value){
				console.log(value);
				this.fromAccountValue = value;
			},
			
			changePhone(value) {
			  var len = value.length;
			  var x = value.substring(3, len - 4);
			  var values = value.replace(x, "****");
			  return values;
			},
		
			// 保存资料
			submitHandler() {

		
				// this.submitStatus = true;
				if (this.transformValue === '') {
					this.$common.errorToShow('请输入转账金额')
					// this.submitStatus = false;
					return;
				} 
				
				
				if (this.moneyToUserName === '' && this.isCheckValue==1) {
					this.$common.errorToShow('请输入转账账户')
					// this.submitStatus = false;
					return;
				} 
				
				if (this.touser_nickname === '' && this.isCheckValue==1) {
					this.$common.errorToShow('请输入转账账户昵称')
					// this.submitStatus = false;
					return;
				} 
				
				if (this.code === '') {
					this.$common.errorToShow('请输入验证码')
					// this.submitStatus = false;
					return;
				} 
				
				if (this.isCheckValue == 0){
					
		
					
					let data = {
						code: this.code,
						money: this.transformValue,
						token : this.$db.get("userToken")
					};
					
					
					var _this = this;
					
					
					this.$api.bonus_to_balance(data, res => {
						if (res.status) {
							
							
							this.$common.navigateTo('/pages/myCenter/myTeamList/myAccountList');
													
						
						// 	this.userinfo.bonus = this.userinfo.bonus - this.transformValue;
						
												
						// 	this.userinfo.balance = Number(this.transformValue) + Number(this.userinfo.balance);
										
												
							this.$common.successToShow(res.msg);
						
						} else {
							this.$common.errorToShow(res.msg)
	
						}
					})
					
				}else if(this.fromAccountValue == 0){
					
					
					let data = {
						code: this.code,
						money: this.transformValue,
						token : this.$db.get("userToken"),
						touser : this.moneyToUserName,
						touser_nickname : this.moneyToNickname,
					};
					
					console.log(22222);
					
					console.log(data);
					
					this.$api.transfer(data, res => {
						if (res.status) {
							
							
							this.$common.navigateTo('/pages/myCenter/myTeamList/myAccountList');
													
							
							// this.userinfo.balance = this.userinfo.balance - this.transformValue;
						
							this.$common.successToShow(res.msg);
						
						} else {
							this.$common.errorToShow(res.msg)
						
						}
					})
					
					
				}else{
					
					
					
					let data = {
						code: this.code,
						money: this.transformValue,
						token : this.$db.get("userToken"),
						touser : this.moneyToUserName,
						touser_nickname : this.moneyToNickname,
					};
					
					// console.log(22222);
					
					// 更新
					
					console.log(data);
					
					this.$api.bonus_to_otherbalance(data, res => {
						if (res.status) {
							
							// this.userinfo.balance = this.userinfo.balance - this.transformValue;
							
							
							this.$common.navigateTo('/pages/myCenter/myTeamList/myAccountList');
												
						
							this.$common.successToShow(res.msg);
						
						} else {
							this.$common.errorToShow(res.msg)
						
						}
					})
					
									
					
					
					
				}
				
				
			
				
			},
			// 发送短信验证码
			sendCode() {
				
			
			
			this.$common.loadToShow('发送中...');
			setTimeout(() => {
				this.$common.loadToHide();
				this.$api.sms({
					mobile: this.mobile,
					code: 'tran'
				}, res => {
					if (res.status) {
						this.timer = 60;
						this.verification = false;
						this.$common.successToShow(res.msg);
						this.countDown(); // 执行验证码计时
					} else {
						this.$common.errorToShow(res.msg);
					}
				});
			}, 1000);
				
			},
		
			// 验证码倒计时
			countDown() {
				let auth_timer = setInterval(() => {
					// 定时器设置每秒递减
					this.timer--; // 递减时间
					uni.setStorage({
						key: 'timer',
						data: this.timer,
						success: function() {}
					});
					if (this.timer <= 0) {
						this.verification = true; // 60s时间结束还原v-show状态并清除定时器
						clearInterval(auth_timer);
					}
				}, 1000);
			},
		
		},
		
		onShow() {
			
			if (isMemberWeb==false){
				this.isCheckValue = 1;
			}
			
			let _this = this;
			_this.timer = parseInt(_this.$db.get('timer'));
			_this.new_timer = parseInt(_this.$db.get('new_timer'));
			if (_this.timer != null && _this.timer > 0) {
				_this.countDown();
				_this.verification = false;
			}
			if (_this.new_timer != null && _this.new_timer > 0) {
				_this.new_countDown();
				_this.new_verification = false;
			}
			_this.$api.userInfo({}, function(res) {
				if (res.status) {
					_this.mobile = res.data.mobile;
					_this.userinfo = res.data;
					_this.showPhone = _this.changePhone(_this.mobile);
					
					console.log(_this.showPhone);
					
				} else {
					//报错了
					_this.$common.errorToShow(res.msg);
				}
			});
		},
		
		onLoad: function() {
			
			if (isMemberWeb==false){
				this.isCheckValue = 1;
			}
			
			let _this = this;
			_this.timer = parseInt(_this.$db.get('timer'));
			_this.new_timer = parseInt(_this.$db.get('new_timer'));
			if (_this.timer != null && _this.timer > 0) {
				_this.countDown();
				_this.verification = false;
			}
			if (_this.new_timer != null && _this.new_timer > 0) {
				_this.new_countDown();
				_this.new_verification = false;
			}
			_this.$api.userInfo({}, function(res) {
				if (res.status) {
					_this.mobile = res.data.mobile;
					_this.userinfo = res.data;
					_this.showPhone = _this.changePhone(_this.mobile);
					
					console.log(_this.showPhone);
					
				} else {
					//报错了
					_this.$common.errorToShow(res.msg);
				}
			});
		}
	}
</script>

<style>
	
	page{
		background: #FFFFFF;
	}
	
	.user-head {
		height: 100upx;
	}

	.user-head-img {
		height: 90upx;
		width: 90upx;
		border-radius: 50%;
	}

	.cell-hd-title {
		color: #333;
	}

	.cell-item-bd {
		color: #666;
		font-size: 26upx;
	}

	.cell-item-hd {
		width: 160rpx;
	}
	
	.headCheck{
		
		width: 100%;
		
		margin-top: 50upx;
		
		height: 100upx;
		
		display: flex;

		flex-direction: row;
		
		/* background-color: #007AFF; */
		
		align-items: center;
	}
	
	.bountsHeaderView{
		margin-left: 30upx;
		color: #333333;
	}
	
	
	
	.cell-bd-input{
		
		color: #333333;
		
		font-size: 28upx;
		
	}
	
	
	.checkBox{
		
		width: 35upx;
		
		height: 35upx;
		
	
		
		/* background: #007AFF; */
		
		border: #007AFF;
		
		border-color: #FF0000;
		
		border-style: solid;

		border-width: 3upx;
		
		border-radius: 50%;
		
	
		
		display: flex;
		
		flex-direction: row;
		
		align-items: center;
		
		justify-content: center;
		
	}
	
	.pointView{
		
		
		width: 10upx;
		
		height: 10upx;
		
			

		
		background-color: #FF0000;
		
		border-radius: 50%;
		
		
	}
	
	.suplusAccountView{
		
		margin-left: 10upx;
		color: #FF0000;
		
		
	}
	
	.btn2{
		color: #333333;
	}
	
	
	

</style>
